//app.js
App({
  onLaunch: function () {},
  initNum: 0,
  globalData: {
    loginRuning: false,
    loginCollect: [],
    userInfo: '',
    location:'',
    token: ""
  },

  setStorage: function (key, data, callback=function(){}, reject=function(){}) {
    try {
      wx.setStorageSync(key, data);
      this.globalData[key] = data;
      console.log(`Method:setStorage(success),Value:{${key}:${data}}`);
      callback(data)
    } catch (e) {
      reject(e)
    }
  },
  getStorageByKey: function (key) {
    var storage;
    if (!!this.globalData[key]) {
      return this.globalData[key];
    } else {
      try {
        const value = wx.getStorageSync(key)
        if (value) {
          console.log(`Method:getStorageByKey(success),Value:{${key}:${value}}`);
          storage = value;
          return storage;
        }
      } catch (e) {
        console.warn("getStorageByKey-fail:" + key);
      }
    }
    return !!storage ? storage : "";
  }
})